package com.turman.cnw.tools

import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.graphics.drawable.Drawable
import android.widget.TextView
import androidx.appcompat.widget.AppCompatImageView
import androidx.databinding.BindingAdapter
import androidx.databinding.BindingConversion
import androidx.databinding.BindingMethod
import androidx.databinding.BindingMethods
import com.turman.cnw.R

@BindingMethods(
    BindingMethod(type=AppCompatImageView::class,attribute = "image",method="setImageDrawable"))
object BindingTools {
}

@BindingAdapter("android:textColor", requireAll = false)
fun getColorId(view:TextView, type:Int) {
    val color = when(type){
        0-> R.color.black
        1-> R.color.purple_200
        2-> R.color.teal_200
        else-> R.color.teal_700
    }
    view.setTextColor(view.resources.getColor(color))
}

@BindingConversion
fun str2color(str:String):Drawable {
    return when(str) {
        "red"->ColorDrawable(Color.RED)
        "blue"-> ColorDrawable(Color.BLUE)
        else-> ColorDrawable(Color.YELLOW)
    }
}

